package com.sr.demo.response;

import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * 操作返回
 * @author liushuai
 * @date 2019/11/3 19:05
 */
@Data
@NoArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = false)
public class NuoResult<T> {
    private String message;
    private Object data;
    private int total;


    public NuoResult(String message) { ;
        this.message = message;
    }


    public NuoResult( String message, Object data) {
        this.message = message;
        this.data = data;
    }

    public NuoResult( String message, Object data,int total) {
        this.message = message;
        this.data = data;
        this.total = total;
    }

    /**
     * 有数据的返回值
     * @param data
     * @param <T>
     * @return
     */
    public static <T> NuoResult<T> buildResponse(NuoSuccessStatus responseCode, T data) {
        return new NuoResult<T>(responseCode.toString(),data);
    }

    /**
     * 有数据的返回值带总数
     * @param data
     * @param <T>
     * @return
     */
    public static <T> NuoResult<T> buildResponse(NuoSuccessStatus responseCode, T data,int total) {
        return new NuoResult<T>(responseCode.toString(),data,total);
    }

    /**
     * 保存操作无返回
     * @param <T>
     * @return
     */
    public static <T> NuoResult<T> buildResponse(NuoSuccessStatus responseCode) {
        return new NuoResult<T>(responseCode.toString());
    }

}
